package data.trade;

import java.util.ArrayList; 
import data.ListInterIterator;

public class Tradefind {
	ArrayList<Trade> trades;
	ArrayList<Trade> find=new ArrayList<Trade>();
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Tradefind (ListInterIterator listInterIterator){
		this.trades=(ArrayList<Trade>) listInterIterator.toArray();
	}
	
	public ListInterIterator <Trade> find(String key,String message){
		if(key.equals("vipID")){
			findByVipID(message);
		}
		else if(key.equals("clerkID")){
			findByClerkID(message);
		}
		else if(key.equals("date")){
			findByTime(message);
		}
		return new ListInterIterator<Trade>(find);
	}

	private void findByVipID(String message){
		for(int i=0;i<trades.size();i++){
			if(trades.get(i).getVipID().equals(message)){
				find.add(trades.get(i));
			}
		}
	}
	private void findByClerkID(String message){
		for(int i=0;i<trades.size();i++){
			if(trades.get(i).getClerkID().equals(message)){
				find.add(trades.get(i));
			}
		}
	}
	
	private void findByTime(String message){
		for(int i=0;i<trades.size();i++){
			if(trades.get(i).getTime().equals(message)){
				find.add(trades.get(i));
			}
		}
	}
}
